﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using Business_Layer;
public partial class Default2 : System.Web.UI.Page
{
    Customer_BUS cusBUS = new Customer_BUS();
    CustomerDTO cusDTO = new CustomerDTO();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public static string GetMD5Hash(string input)
    {
        System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
        bs = x.ComputeHash(bs);
        System.Text.StringBuilder s = new System.Text.StringBuilder();
        foreach (byte b in bs)
        {
            s.Append(b.ToString("x2").ToLower());
        }
        string password = s.ToString();
        return password;
    }

    protected void btCapNhat_Click(object sender, EventArgs e)
    {
        IList<CustomerDTO> list = cusBUS.GetListAll();
        for (int i=0; i<list.Count(); i++)
        {
            if(txtTendangnhap.Text!= list[i].UserName)
            {
                //ten dnhap da co
            }
           
        }
        string matkhau1 =GetMD5Hash(txtMatkhau1.Text);
        string matkhau2=GetMD5Hash(txtMatkhau2.Text);
        if (matkhau1 != matkhau2)
        {
           //nhac lai mat khau
        }
        cusDTO.ID = cusBUS.CountList() + 1;
        cusDTO.Password = matkhau1;
        cusDTO.PersonalID = txtCMND.Text;
        cusDTO.UserName = txtTendangnhap.Text;
        cusDTO.Address = txtDiachi.Text;
        if (cusBUS.InsertCustomer(cusDTO) == 1)
        {
            //dk thanh cong
        }
        else
        {
            //dang ky khong thanh cong
        }
    }
} 